15 RANDOMIZE : SCREEN 1 : CLS : W% = 10 : H% = 20
40 DIM FIG!(6,3,3,3), SCR!(H%, W%+1)
50 FOR I%=0 TO H%-1 : SCR!(I%, 0) = TRUE :
60 SCR!(I%, W%+1) = TRUE : NEXT I%
70 FOR I%=1 TO W% : SCR!(H%, I%) = TRUE : NEXT I%
90 FIG!(0,0,1,1) = TRUE : FIG!(0,0,1,2) = TRUE
91 FIG!(0,0,2,1) = TRUE : FIG!(0,0,2,2) = TRUE
92 FIG!(0,1,1,1) = TRUE : FIG!(0,1,1,2) = TRUE
93 FIG!(0,1,2,1) = TRUE : FIG!(0,1,2,2) = TRUE
94 FIG!(0,2,1,1) = TRUE : FIG!(0,2,1,2) = TRUE
95 FIG!(0,2,2,1) = TRUE : FIG!(0,2,2,2) = TRUE
96 FIG!(0,3,1,1) = TRUE : FIG!(0,3,1,2) = TRUE
97 FIG!(0,3,2,1) = TRUE : FIG!(0,3,2,2) = TRUE
99 FIG!(1,0,1,0) = TRUE : FIG!(1,0,1,1) = TRUE
100 FIG!(1,0,1,2) = TRUE : FIG!(1,0,1,3) = TRUE
101 FIG!(1,1,0,1) = TRUE : FIG!(1,1,1,1) = TRUE
102 FIG!(1,1,2,1) = TRUE : FIG!(1,1,3,1) = TRUE
103 FIG!(1,2,1,0) = TRUE : FIG!(1,2,1,1) = TRUE
104 FIG!(1,2,1,2) = TRUE : FIG!(1,2,1,3) = TRUE
105 FIG!(1,3,0,1) = TRUE : FIG!(1,3,1,1) = TRUE
106 FIG!(1,3,2,1) = TRUE : FIG!(1,3,3,1) = TRUE
108 FIG!(2,0,1,1) = TRUE : FIG!(2,0,2,0) = TRUE
109 FIG!(2,0,2,1) = TRUE : FIG!(2,0,2,2) = TRUE
110 FIG!(2,1,0,1) = TRUE : FIG!(2,1,1,1) = TRUE
111 FIG!(2,1,2,1) = TRUE : FIG!(2,1,1,2) = TRUE
112 FIG!(2,2,2,1) = TRUE : FIG!(2,2,1,0) = TRUE
113 FIG!(2,2,1,1) = TRUE : FIG!(2,2,1,2) = TRUE
114 FIG!(2,3,0,1) = TRUE : FIG!(2,3,1,1) = TRUE
115 FIG!(2,3,2,1) = TRUE : FIG!(2,3,1,0) = TRUE
117 FIG!(3,0,0,1) = TRUE : FIG!(3,0,1,1) = TRUE
118 FIG!(3,0,2,1) = TRUE : FIG!(3,0,0,2) = TRUE
119 FIG!(3,1,1,0) = TRUE : FIG!(3,1,1,1) = TRUE
120 FIG!(3,1,1,2) = TRUE : FIG!(3,1,2,2) = TRUE
121 FIG!(3,2,0,2) = TRUE : FIG!(3,2,1,2) = TRUE
122 FIG!(3,2,2,2) = TRUE : FIG!(3,2,2,1) = TRUE
123 FIG!(3,3,0,1) = TRUE : FIG!(3,3,1,1) = TRUE
124 FIG!(3,3,1,2) = TRUE : FIG!(3,3,1,3) = TRUE
126 FIG!(4,0,0,1) = TRUE : FIG!(4,0,0,2) = TRUE
127 FIG!(4,0,1,2) = TRUE : FIG!(4,0,2,2) = TRUE
128 FIG!(4,1,1,3) = TRUE : FIG!(4,1,2,1) = TRUE
129 FIG!(4,1,2,2) = TRUE : FIG!(4,1,2,3) = TRUE
130 FIG!(4,2,0,1) = TRUE : FIG!(4,2,1,1) = TRUE
131 FIG!(4,2,2,1) = TRUE : FIG!(4,2,2,2) = TRUE
132 FIG!(4,3,1,1) = TRUE : FIG!(4,3,1,2) = TRUE
133 FIG!(4,3,1,3) = TRUE : FIG!(4,3,2,1) = TRUE
135 FIG!(5,0,0,2) = TRUE : FIG!(5,0,1,1) = TRUE
136 FIG!(5,0,1,2) = TRUE : FIG!(5,0,2,1) = TRUE
137 FIG!(5,1,1,1) = TRUE : FIG!(5,1,1,2) = TRUE
138 FIG!(5,1,2,2) = TRUE : FIG!(5,1,2,3) = TRUE
139 FIG!(5,2,0,2) = TRUE : FIG!(5,2,1,1) = TRUE
140 FIG!(5,2,1,2) = TRUE : FIG!(5,2,2,1) = TRUE
141 FIG!(5,3,1,1) = TRUE : FIG!(5,3,1,2) = TRUE
142 FIG!(5,3,2,2) = TRUE : FIG!(5,3,2,3) = TRUE
144 FIG!(6,0,0,1) = TRUE : FIG!(6,0,1,1) = TRUE
145 FIG!(6,0,1,2) = TRUE : FIG!(6,0,2,2) = TRUE
146 FIG!(6,1,1,2) = TRUE : FIG!(6,1,1,3) = TRUE
147 FIG!(6,1,2,1) = TRUE : FIG!(6,1,2,2) = TRUE
148 FIG!(6,2,0,1) = TRUE : FIG!(6,2,1,1) = TRUE
149 FIG!(6,2,1,2) = TRUE : FIG!(6,2,2,2) = TRUE
150 FIG!(6,3,1,2) = TRUE : FIG!(6,3,1,3) = TRUE
151 FIG!(6,3,2,1) = TRUE : FIG!(6,3,2,2) = TRUE
152 PRD = 1 : SP% = 8 : RES!=FALSE : CFY%=-3
192 GOSUB 10000 : GOSUB 5000 : GOSUB 3000
195 REM
200 CT = TIME() : IF CT < CYC THEN GOTO 225
210 CYC = CT+PRD-STG%/3000 : STG% = STG%+1 : GOSUB 1000
225 K$ = GET$() : IF K$ = "q" THEN GOTO 30000
235 IF K$ = "a" THEN MV% = -1 : GOSUB 2000
240 IF K$ = "d" THEN MV% = 1 : GOSUB 2000
245 IF K$ = "s" THEN GOSUB 1000
250 IF K$ = "w" THEN GOSUB 9000
990 GOTO 195
1000 REM
1005 X% = CFX% : Y% = CFY%+1 : GOSUB 6000
1020 IF RES! THEN GOTO 1055
1025 RES! = FALSE : GOSUB 4000 : CFY% = Y% : RES! = TRUE : GOSUB 4000
1050 RETURN
1055 IF CFY% < 1 THEN GOTO 30000
1056 SC% = SC%+1 : GOSUB 3000
1060 FOR I%=0 TO 3 : FOR J% = 0 TO 3 : IF CFY%+J% < 0 THEN GOTO 1085
1075 IF FIG!(CFG%, CFP%, J%, I%) = FALSE THEN GOTO 1085
1080 SCR!(CFY%+J%, CFX%+I%+1) = TRUE
1085 NEXT J% : NEXT I%
1095 GOSUB 7000 : GOSUB 5000 : CFX% = 0 : CFY% = -3 : CFG% = RND() * 7
1990 RETURN
2000 REM
2005 X% = CFX%+MV% : Y% = CFY% : GOSUB 6000 : IF RES! THEN GOTO 2990
2025 RES! = FALSE : GOSUB 4000 : CFX% = X% : RES! = TRUE : GOSUB 4000
2990 RETURN
3000 REM
3005 COLOR 1,0 : LOCATE 4,18 : PRINT SC%
3990 RETURN
4000 REM
4005 IF RES! THEN COLOR 0,1 : GOTO 4015
4010 COLOR 1,0
4015 FOR I%=0 TO 3 : FOR J%=0 TO 3
4025 IF CFY%+J% < 0 THEN GOTO 4040
4030 IF FIG!(CFG%, CFP%, J%, I%) = FALSE THEN  GOTO 4040
4035 BOX (SP%+(CFX%+I%)*SP%),(CFY%+J%)*SP%,SP%,SP%
4040 NEXT J% : NEXT I%
4990 RETURN
5000 REM
5025 COLOR 0,0 : BOX (SP%), 0, W%*SP%, H%*SP% : COLOR 1, 0
5040 FOR I%=0 TO H%-1
5045 LINE (SP%), I%*SP%, (W%+1)*SP%, I%*SP%
5050 NEXT I% : FOR I%=2 TO W%
5060 LINE (I%*SP%), 0, I%*SP%, H%*SP%
5065 NEXT I% : COLOR 0,1 : FOR I%=1 TO W% : FOR J% = 0 TO H%-1
5085 IF SCR!(J%, I%) = FALSE THEN GOTO 5095
5090 BOX (I%*SP%), J%*SP%, SP%, SP%
5095 NEXT J% : NEXT I%
5990 RETURN
6000 REM
6005 RES! = FALSE : FOR I%=0 TO 3 : FOR J% = 0 TO 3
6020 IF X%+I%+1 < 0 THEN GOTO 6045
6025 IF Y%+J% < 0 THEN GOTO 6045
6030 IF FIG!(CFG%, CFP%, J%, I%) = FALSE THEN GOTO 6045
6035 IF SCR!(Y%+J%, X%+I%+1) = FALSE THEN GOTO 6045
6040 RES! = TRUE
6045 NEXT J% : NEXT I%
6990 RETURN
7000 REM
7005 DL! = FALSE : FOR I% = H%-1 TO 1 STEP -1 : RES! = TRUE
7020 FOR J% = 1 TO W% : IF SCR!(I%, J%) = FALSE THEN RES! = FALSE
7030 NEXT J% : IF RES! THEN DL! = TRUE : Y% = I% : GOSUB 8000
7035 NEXT I%
7040 IF DL! THEN GOTO 7005
7990 RETURN
8000 REM
8005 FOR K% = 1 TO W% : SCR!(Y%,K%) = FALSE : NEXT K%
8020 GOSUB 5000 : DELAY 300
8035 FOR K% = Y% TO 1 STEP -1 : FOR L% = 1 TO W%
8045 SCR!(K%,L%) = SCR!(K%-1, L%) : NEXT L% : NEXT K%
8060 FOR K% = 1 TO W% : SCR!(0,K%) = FALSE : NEXT K%
8075 GOSUB 5000 : DELAY 300 : SC% = SC%+10 : GOSUB 3000
8990 RETURN
9000 REM
9005 T% = CFP% : CFP% = CFP%+1 : IF CFP% > 3 THEN CFP% = 0
9020 X%=CFX% : Y%=CFY% : GOSUB 6000
9035 IF RES! THEN CFP% = T% : GOTO 9990
9040 T1% = CFP% : CFP% = T% : RES! = FALSE : GOSUB 4000
9060 CFP% = T1% : RES! = TRUE : GOSUB 4000
9990 RETURN
10000 REM
10005 COLOR 1,0 : BOX 100,18,40,15 : COLOR 1,1
10020 BOX 0,0,SP%,(H%+1)*SP%
10025 BOX (W%+1)*SP%,0,SP%,(H%+1)*SP%
10030 BOX (SP%), H%*SP%, W%*SP%, SP%
10035 LOCATE 2,18 : PRINT "POINTS"
10045 LOCATE 7,20 : PRINT "TERMINAL-BASIC"
10055 LOCATE 9,21 : PRINT "TETRIS V 1.0"
10990 RETURN
30000 REM
30005 SCREEN 0 : PRINT "YOU'V GOT";SC%;"POINTS"
30010 END
